package com.sx.entity.finance;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sx.basic.BasicEntity;
import com.sx.basic.serializer.BigDecimalToStringSerializer;
import com.sx.entity.user.AmountEntity;
import com.sx.utils.DateUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.*;
import java.math.BigDecimal;

/**
 * @author AdinZ
 * @date 2020/11/18 17:54
 */
@Data
@TableName(value = "sx_finance_income")
@Entity
@Table(name = "sx_finance_income")
@ApiModel(value = "用户资金收支明细")
public class IncomeEntity extends BasicEntity {

    @Id
    @GeneratedValue
    @TableId(type = IdType.ASSIGN_ID)
    private Long id;

    @ApiModelProperty("用户id")
    private long uid;

    @ApiModelProperty("账户金额类型")
    @Enumerated(EnumType.STRING)
    private AmountEntity.AmountType type;

    @ApiModelProperty("金额交易前")@Column(columnDefinition = "decimal(18,4)")
    @JSONField(serializeUsing = BigDecimalToStringSerializer.class)
    private BigDecimal beforeAmount=BigDecimal.ZERO;

    @ApiModelProperty("金额")@Column(columnDefinition = "decimal(18,4)")
    @JSONField(serializeUsing = BigDecimalToStringSerializer.class)
    private BigDecimal amount=BigDecimal.ZERO;

    @ApiModelProperty("金额交易后")@Column(columnDefinition = "decimal(18,4)")
    @JSONField(serializeUsing = BigDecimalToStringSerializer.class)
    private BigDecimal afterAmount=BigDecimal.ZERO;

    @ApiModelProperty("金额表创建时间")
    private long created=System.currentTimeMillis();

    @TableField("_year")
    @Column(name = "_year",length = 10)
    private String year;

    @TableField("_month")
    @Column(name = "_month",length = 10)
    private String month;

    @Column(name = "_day",length = 10)
    @TableField("_day")
    private String day;

    /**
     * 属性表, 可以放一些自定义内容,
     * 最好是json 字符串
     */
    @ApiModelProperty("属性表")
    @Column(columnDefinition = "text")
    private String attribute;

    @ApiModelProperty("来源类型")
    @Column(length = 20)@Enumerated(EnumType.STRING)
    private SourceType sourceType;

    @ApiModelProperty("来源id")
    private Long sourceId;

    @ApiModelProperty("是否隐藏")
    private boolean hidden;



    public IncomeEntity(){
        this.day=DateUtils.format("yyyy-MM-dd");
        this.month=DateUtils.format("yyyy-MM");
        this.day=DateUtils.format("yyyy");
    }


    public enum SourceType{
        /**
         * 用户资金明细记录,来源类型
         * 可根据自己需求添加 枚举类型
         */
    }


}
